using OneCaps.Core.Entity;
using OneCaps.Core.Enum;
using OneCaps.Core.Models;

namespace OneCaps.Core.Interfaces
{
    /// <summary>
    /// 计费服务接口
    /// </summary>
    public interface IBillingService
    {
        /// <summary>
        /// 计算停车费用
        /// </summary>
        Task<Money> CalculateParkingFeeAsync(int parkingRecordId);

        /// <summary>
        /// 计算停车费用（指定时长）
        /// </summary>
        Task<Money> CalculateParkingFeeAsync(TimeSpan duration, VehicleType vehicleType, ParkingSpaceType? spaceType = null, bool isVip = false);

        /// <summary>
        /// 应用收费规则
        /// </summary>
        Task<BillingRule> ApplyBillingRuleAsync(int parkingRecordId);

        /// <summary>
        /// 获取适用的收费规则
        /// </summary>
        Task<BillingRule?> GetApplicableBillingRuleAsync(VehicleType vehicleType, ParkingSpaceType? spaceType = null, bool isVip = false);

        /// <summary>
        /// 创建收费规则
        /// </summary>
        Task<BillingRule> CreateBillingRuleAsync(BillingRule rule);

        /// <summary>
        /// 更新收费规则
        /// </summary>
        Task<BillingRule> UpdateBillingRuleAsync(BillingRule rule);

        /// <summary>
        /// 删除收费规则
        /// </summary>
        Task DeleteBillingRuleAsync(int ruleId);

        /// <summary>
        /// 获取所有收费规则
        /// </summary>
        Task<IEnumerable<BillingRule>> GetAllBillingRulesAsync();

        /// <summary>
        /// 获取有效的收费规则
        /// </summary>
        Task<IEnumerable<BillingRule>> GetValidBillingRulesAsync();

        /// <summary>
        /// 启用收费规则
        /// </summary>
        Task EnableBillingRuleAsync(int ruleId);

        /// <summary>
        /// 禁用收费规则
        /// </summary>
        Task DisableBillingRuleAsync(int ruleId);

        /// <summary>
        /// 应用优惠券
        /// </summary>
        Task<Money> ApplyCouponAsync(int parkingRecordId, string couponCode);

        /// <summary>
        /// 验证优惠券
        /// </summary>
        Task<bool> ValidateCouponAsync(string couponCode);

        /// <summary>
        /// 获取优惠券信息
        /// </summary>
        Task<CouponInfo?> GetCouponInfoAsync(string couponCode);

        /// <summary>
        /// 生成收费单
        /// </summary>
        Task<BillingInvoice> GenerateInvoiceAsync(int parkingRecordId);

        /// <summary>
        /// 获取收费统计
        /// </summary>
        Task<BillingStatistics> GetBillingStatisticsAsync(DateTime startDate, DateTime endDate);
    }

    /// <summary>
    /// 优惠券信息
    /// </summary>
    public class CouponInfo
    {
        public string Code { get; set; } = string.Empty;
        public string Name { get; set; } = string.Empty;
        public decimal DiscountAmount { get; set; }
        public decimal DiscountRate { get; set; }
        public DateTime ExpiryDate { get; set; }
        public bool IsValid { get; set; }
        public string? Description { get; set; }
    }

    /// <summary>
    /// 收费单
    /// </summary>
    public class BillingInvoice
    {
        public int Id { get; set; }
        public string InvoiceNumber { get; set; } = string.Empty;
        public DateTime IssueDate { get; set; }
        public Money TotalAmount { get; set; } = Money.Zero();
        public Money DiscountAmount { get; set; } = Money.Zero();
        public Money FinalAmount { get; set; } = Money.Zero();
        public string? Remarks { get; set; }
    }

    /// <summary>
    /// 收费统计
    /// </summary>
    public class BillingStatistics
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int TotalRecords { get; set; }
        public Money TotalRevenue { get; set; } = Money.Zero();
        public Money TotalDiscount { get; set; } = Money.Zero();
        public Dictionary<PaymentMethod, Money> RevenueByPaymentMethod { get; set; } = new();
        public Dictionary<VehicleType, int> RecordsByVehicleType { get; set; } = new();
    }
} 